const state = {
	caches: []//缓存列表
}

const getters = {
	GET (state) {
		return state.caches
	}
}

const mutations = {
	SET (state, caches) {
		state.caches = caches
	}
}

const actions = {
	add ({state, commit}, cache) {
		const caches = [...state.caches]
		const index = caches.findIndex(c => c.origin == cache.origin)
		if ( index > -1 ) caches[index] = cache
		else caches.push(cache)
		commit('SET', caches)
	},
	remove ({state, commit}, origin) {
		const caches = [...state.caches]
		const index = caches.findIndex(c => c.origin == origin)
		if( index > -1 ) caches.splice(index, 1)
		commit('SET', caches)
	},
	clear ({commit}) {
		commit('SET', [])
	}
}

export default {
    namespaced: true,
    state,
    getters,
	mutations,
	actions
}